<template>
  <div class="page-bg">
    <div class="ta-search-box">
      <el-form ref="searchForm" :inline="true" :model="searchForm">
        <el-form-item label="算法">
          <el-select v-model="searchForm.type" placeholder="请选择">
            <el-option
              class="expand-indent"
              v-for="item in typeOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否评论">
          <el-select v-model="searchForm.status" placeholder="请选择">
            <el-option
              class="expand-indent"
              v-for="item in statusOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否加急">
          <el-select v-model="searchForm.urgent" placeholder="请选择">
            <el-option
              class="expand-indent"
              v-for="item in urgentOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item class="text-right">
          <el-button type="primary" @click="handSubmit('form')">
            搜索
          </el-button>
        </el-form-item>
      </el-form>
    </div>
    <div
      v-if="showMessage == 1"
      class="ta-table-box"
      style="background-color: aliceblue; margin-bottom: 15px"
    >
      专家未读消息数量： {{ noReadMessageCount }}
    </div>
    <div class="ta-table-box">
      <el-table :data="tableData" border style="width: 100%">
        <el-table-column :key="0" prop="date" label="日期"></el-table-column>
        <el-table-column
          :key="1"
          prop="type"
          label="算法类型"
          :formatter="formatterType"
        ></el-table-column>
        <el-table-column
          v-if="searchForm.type == 0"
          :key="2"
          prop="finPic"
          label="指纹图像"
        >
          <template slot-scope="scope">
            <img
              :src="scope.row.finPic"
              alt
              style="display: block; height: 100px; max-width: 100px"
            />
          </template>
        </el-table-column>

        <el-table-column
          v-if="searchForm.type == 1"
          :key="3"
          prop="fakePic"
          label="笔迹图像1"
          width="180"
        >
          <template slot-scope="scope">
            <img
              :src="scope.row.fakePic"
              alt
              style="display: block; height: 100px; max-width: 100px"
            />
          </template>
        </el-table-column>
        <el-table-column
          v-if="searchForm.type == 1"
          :key="4"
          prop="realPic"
          label="笔迹图像2"
          width="180"
        >
          <template slot-scope="scope">
            <img
              :src="scope.row.realPic"
              alt
              style="display: block; height: 100px; max-width: 100px"
            />
          </template>
        </el-table-column>

        <el-table-column
          v-if="searchForm.type == 0"
          :key="5"
          prop="rate"
          label="假指纹概率"
        >
        </el-table-column>

        <el-table-column
          v-if="searchForm.type == 1"
          :key="6"
          prop="rate"
          label="笔迹相似度"
          width="120"
        >
        </el-table-column>
        <el-table-column
          v-if="searchForm.type == 0"
          :key="7"
          prop="isTrue"
          label="是否是真指紋"
          :formatter="formatterResult"
        >
        </el-table-column>
        <el-table-column
          v-if="roleType == 1 || roleType == 0"
          :key="8"
          prop="comment"
          label="专家评论"
          width="180"
        >
        </el-table-column>
        <el-table-column
          v-if="(roleType == 1 || roleType == 0) && searchForm.type == 0"
          :key="9"
          prop="finResult"
          label="专家鉴定指纹结果"
          width="80"
          :formatter="formatterFinResult"
        >
        </el-table-column>
        <el-table-column
          v-if="(roleType == 1 || roleType == 0) && searchForm.type == 1"
          :key="10"
          prop="signResult"
          label="专家鉴定签名结果"
          :formatter="formatterSignResult"
          width="80"
        >
        </el-table-column>

        <el-table-column align="left" fixed="right" label="操作">
          <template #default="scope">
            <el-button
              v-if="roleType == 1"
              icon="el-icon-edit"
              size="small"
              type="text"
              @click="editComment(scope.row)"
              >修改评论或专家鉴定结果</el-button
            >
            <!-- <el-button
              icon="el-icon-delete"
              size="small"
              type="text"
              @click="deleteRecord(scope.row)"
              >删除记录</el-button
            > -->
          </template>
        </el-table-column>
      </el-table>
      <div class="ta-pagination">
        <el-pagination
          :current-page="page"
          :page-size="pageSize"
          :page-sizes="[5, 10, 20, 50]"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange"
        />
      </div>
    </div>

    <el-dialog
      :visible.sync="dialogFormVisible"
      :before-close="closeDialog"
      title="修改评价信息"
      width="440px"
      center
    >
      <el-form
        ref="dialogform"
        :model="dialogForm"
        :rules="dialogRules"
        label-width="140px"
      >
        <el-form-item label="评论" prop="comment">
          <el-input v-model="dialogForm.comment" autocomplete="off" />
        </el-form-item>
        <el-form-item
          :label="searchForm.type == 0 ? '鉴定结果' : '是否同一個人'"
          prop="result"
        >
          <el-select v-model="dialogForm.result" placeholder="请选择">
            <el-option
              class="expand-indent"
              v-for="item in resultOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button size="small" @click="closeDialog">取 消</el-button>
          <el-button size="small" type="primary" @click="enterDialog"
            >确 定</el-button
          >
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import {
  queryIdentRecordByUser,
  editIdentRecordByExpert,
  deleteIdentRecordByExpert,
  noReadMessage,
} from "@/api/modules/fingerprint";
import Constants from "@/constants";
export default {
  name: "finRecord",
  data() {
    return {
      searchForm: {
        type: 0,
        status: 0,
        urgent: 0,
        pagenum: 1,
        pagesize: 5,
        urgent: 0,
      },
      tableData: [],
      roleValue: 2,
      typeOptions: [
        {
          value: 0,
          label: "指纹算法",
        },
        {
          value: 1,
          label: "笔迹算法",
        },
      ],
      statusOptions: [
        {
          value: 0,
          label: "全部",
        },
        {
          value: 1,
          label: "已评论",
        },
        {
          value: 2,
          label: "未评论",
        },
      ],
      urgentOptions: [
        {
          value: 0,
          label: "全部",
        },
        {
          value: 1,
          label: "加急",
        },
      ],
      resultOptions: [
        {
          value: 0,
          label: "假",
        },
        {
          value: 1,
          label: "真",
        },
      ],
      dialogFormVisible: false,
      dialogForm: {
        comment: "",
        result: 0,
      },
      dialogRules: {
        comment: [
          {
            required: true,
            message: "评论不能为空!",
            trigger: "blur",
          },
        ],
        result: [
          {
            required: true,
            message: "鉴定结果不能为空!",
            trigger: "blur",
          },
        ],
      },
      noReadMessageCount: 0,
      showMessage: 0,
      page: 1,
      pageSize: 5,
      total: 0,
    };
  },
  computed: {
    roleType() {
      return localStorage.getItem("userRole");
    },
  },
  created() {
    this.queryTableData();
    this.fetchNoReadMessage();
    this.showMessage = localStorage.getItem("userRole");
  },
  methods: {
    queryTableData() {
      this.searchForm.userid = localStorage.getItem("userId");
      this.searchForm.pagenum = this.page;
      this.searchForm.pagesize = this.pageSize;
      queryIdentRecordByUser(this.searchForm).then((res) => {
        this.loading = false;
        if (res.code == 200) {
          this.tableData = res.obj;
          this.total = res.obj[0].count;
        } else {
          this.$message({
            message: res.message,
            type: "error",
          });
        }
      });
    },
    handleCurrentChange(page) {
      this.page = page;
      this.queryTableData();
    },
    handleSizeChange(size) {
      this.pageSize = size;
      this.queryTableData();
    },
    handleClick(row) {
      console.log(row);
    },
    handleAppraisal() {
      this.$router.push({ path: "/appraisal" });
    },
    handSubmit() {
      this.queryTableData();
    },
    editComment(row) {
      console.log(row);
      this.dialogForm.comment = row.comment;
      this.dialogForm.recordId = row.recordId;
      this.dialogForm.result = row.finResult;

      this.dialogFormVisible = true;
    },
    deleteRecord(row) {
      console.log(row);
      let params = {
        recordId: row.recordId,
        userid: localStorage.getItem("userId"),
      };
      deleteIdentRecordByExpert(params).then((res) => {
        if (res.code == 200) {
          this.queryTableData();
        } else {
          this.$message({
            message: res.message,
            type: "error",
          });
        }
      });
    },
    closeDialog() {
      this.dialogFormVisible = false;
    },
    enterDialog() {
      editIdentRecordByExpert(this.dialogForm).then((res) => {
        if (res.code == 200) {
          this.dialogFormVisible = false;
          this.queryTableData();
        } else {
          this.$message({
            message: res.message,
            type: "error",
          });
        }
      });
    },
    fetchNoReadMessage() {
      noReadMessage().then((res) => {
        if (res.code == 200) {
          this.noReadMessageCount = res.obj;
        } else {
          this.$message({
            message: res.message,
            type: "error",
          });
        }
      });
    },
    formatterResult(row, column) {
      if (row.isTrue == 0) {
        return "假";
      } else if (row.isTrue == 1) {
        return "真";
      } else {
        return "";
      }
    },
    formatterFinResult(row, column) {
      if (row.finResult == 0) {
        return "假";
      } else if (row.finResult == 1) {
        return "真";
      } else {
        return "";
      }
    },
    formatterSignResult(row, column) {
      if (row.signResult == 0) {
        return "假";
      } else if (row.signResult == 1) {
        return "真";
      } else {
        return "";
      }
    },
    formatterType(row, column) {
      if (row.type == 0) {
        return "指纹算法";
      } else if (row.type == 1) {
        return "笔迹算法";
      } else {
        return "";
      }
    },
  },
};
</script>

<style lang="scss" scoped></style>
